Let’s play with R Markdown and apply it to the previous pratical exercise
library(hrbrthemes)
library(plotly)
#1-Correlation
library(gapminder)
library(DT)
data = gapminder
datatable(data,rownames = FALSE, filter = "top", options = list(pageLength = 5, scrollX= T))
#Visualisation of the first 6 rows
head(data) #country(fct), continent(fct), year(int), lifeExp(dbl), pop(int), gdpPerCap(dbl)
## # A tibble: 6 x 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
nrow(data) #nb of rows
## [1] 1704
You can also embed plots, for example:
#number of different year?
library(dplyr)
data %>%
select(year) %>%
unique() %>%
nrow()
## [1] 12
library(ggplot2)
#basic scatterplot
data %>%
filter(year =="1952")%>%
ggplot(aes(x = gdpPercap, y = lifeExp)) + geom_point()
p = data %>%
filter(gdpPercap < 90000) %>%
filter( year == 1952) %>%
ggplot(aes(x=gdpPercap, y = lifeExp, color = continent, size = pop)) + geom_point(alpha = 0.5)+theme_ipsum()
ggplotly(p)